package org.kommii.mongodb;

import com.mongodb.BasicDBObject;
import com.mongodb.DBCollection;
import com.mongodb.DBObject;
import com.mongodb.MongoClient;
import com.mongodb.QueryBuilder;
public class Test {

	
	public static void main(String[] args) {
		//uploadcache:store_auth
		//DBCollection coll = Mongodb_ConnPools.getMongoDB_Coll("kami","userinfo");
		for(int i=0;i<10;i++){
			DBCollection coll = Mongodb_ConnPools.getMongoDB_Coll("kami","userinfo");
			DBObject obj = getSimpleUserByWXToken("742b634b-0de1-4810-ab7e-5f99e23c552b",coll);
			System.out.println(obj.get("user_id"));
			System.out.println(obj.get("weixin_user"));
			System.out.println(obj.get("user_head"));
			System.out.println(obj.get("wxtoken"));
		}
		
		//MongoClient mc = null;
		//Mongodb_ConnPools.showConnPoolStatus();
		//long l = coll.count();
		//System.out.println(l);
	}
	
	public static DBObject getSimpleUserByWXToken(String wxtoken,DBCollection c){
		QueryBuilder queryBuilder = QueryBuilder.start();
		DBObject query = queryBuilder.put("wxtoken").is(wxtoken).get();
		BasicDBObject key = new BasicDBObject("fullname",1)
		.append("user_id", 1)
		.append("weixin_user",1)
		.append("user_head", 1)
		.append("wxtoken", 1)
		.append("_id", 0);
		DBObject entity = c.findOne(query,key);
		return entity;
	}

}
